package com.jiot.controller.user;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.CommonEnum;
import com.zg.cloud.annotation.RoleCheck;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.UserFunctionalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.functional.user.FunctionalUserLoginReq;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/11/19 14:52
 * @description
 **/
@RestController
@RequestMapping("/user/functional")
@Api(value = "职能端用户模块")
public class UserFunctionalController {

    @Resource
    private UserFunctionalService userFunctionalService;

    @PostMapping("/login")
    @ApiOperation(value = "职能端用户登录", notes = "user")
    public BaseResponse login(@RequestBody @Valid FunctionalUserLoginReq functionalUserLoginReq) {
        return new BaseResponse(userFunctionalService.login(functionalUserLoginReq));
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @TokenCheck
    @PostMapping("/user/count")
    @ApiOperation(value = "职能端查询职能端用户数量", notes = "user")
    public BaseResponse userCount() {
        return new BaseResponse(userFunctionalService.userCount());
    }
}
